package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itheima.dao.PermissionDao;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.pojo.Permission;
import com.itheima.pojo.Role;
import com.itheima.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service(interfaceClass = PermissionService.class)
@Transactional
public class PermissionServiceImpl implements PermissionService {
    @Autowired
    PermissionDao permissionDao;
    @Override
    //添加权限
    public void add(Permission permission) {
        permissionDao.addPermission(permission);


    }

    @Override
    //分页
    public PageResult pageQuery(QueryPageBean queryPageBean) {
        //从条件对象中获取参数
        Integer currentPage = queryPageBean.getCurrentPage(); // 页码
        Integer pageSize = queryPageBean.getPageSize(); // 每页显示的条数
        String queryString = queryPageBean.getQueryString(); //查询条件
        PageHelper.startPage(currentPage,pageSize);
        List<Permission> list=permissionDao.findByCondition(queryString);
        PageInfo<Permission> permissionPageInfo = new PageInfo<>(list);
        long total = permissionPageInfo.getTotal();
        List<Permission> list1 = permissionPageInfo.getList();
        return new PageResult(total,list1);


    }

    @Override

    public void delete(Integer id) {
             permissionDao.deleteById(id);
    }

    @Override
    public List<Role> findRoleById(Integer id) {
       List<Role> role= permissionDao.findRoleById(id);
       return role;
    }

    @Override
    //根据id查权限
    public Permission findById(Integer id) {
      Permission permission= permissionDao.findById(id);
      return permission;
    }

    @Override
    //更新权限
    public void edit(Permission permission) {
        permissionDao.edit(permission);
    }

    @Override
    public List<Permission> findAll() {
        List<Permission> list = permissionDao.findAll();
        return list;
    }
}
